package com.robot.controller;


import com.robot.common.result.Response;

import com.robot.dao.dto.UserLoginDTO;
import com.robot.dao.entity.User;
import com.robot.dao.vo.UserInfoVO;
import com.robot.service.SmsService;
import com.robot.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.ExecutionException;

@Slf4j
@RestController
@RequestMapping("/login")
@Api(tags = "登录相关")
public class LoginController {

//    @Value("${recaptcha.secret-key}")
//    private String recaptchaSecretKey;

    @Autowired
    private SmsService smsService;

    @Autowired
    private UserService userService;

    @PostMapping("/analyzeKey")
    @ApiOperation("人机交互解析密钥")
    public Response<Boolean> analyzeKey(String key) throws Exception {
        return Response.success(userService.analyzeKey(key));
    }


    @PostMapping("/sendMessage")
    @ApiOperation("发送验证码")
    public Response<String> sendMessage(String userPhone) throws ExecutionException, InterruptedException {
        return Response.success(smsService.sendSmsMessage(userPhone));
    }

    @PostMapping("/register")
    @ApiOperation("用户注册")
    public Response<UserInfoVO> register(@RequestBody UserLoginDTO userLoginDTO) throws Exception {
        UserInfoVO userInfoVO=userService.register(userLoginDTO);
        return Response.success(userInfoVO);
    }


    @PostMapping("/logOn")
    @ApiOperation("用户登录")
    public Response<UserInfoVO> logOn(@RequestBody UserLoginDTO userLoginDTO) throws Exception {
        UserInfoVO userInfoVO=userService.logOn(userLoginDTO);
        return Response.success(userInfoVO);
    }




}
